package com.zcpt.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zcpt.order.IOrderService;
import com.zcpt.pojo.order.Order;
import com.zcpt.pojo.projects.Collection;
import com.zcpt.pojo.projects.Project;
import com.zcpt.projects.ICollectionService;
import com.zcpt.projects.IProjectService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/myHome")
public class OrderController1 {
    @Reference
    private IOrderService orderService;
    @Reference
    private IProjectService projectService;
    @Reference
    private ICollectionService collectionService;

    @GetMapping("/myHome")
    private String findMyOrder(Model model, @RequestParam Integer id) {
        List<Order> orderList = orderService.findMyOrder(id);
        List<Project> projectList = new ArrayList<>();
        for (Order order : orderList) {
            projectList.add(projectService.findProById(order.getProId()));
        }
        List<Collection> collectionList = collectionService.findCollectionByUserId(id);
        List<Project> projectList2 = new ArrayList<>();
        for (Collection collection : collectionList) {
            Project project = projectService.findProById(collection.getProjectId());
            projectList2.add(project);
        }
        System.out.println(projectList.get(0).getProgress() +"------"+projectList.get(0).getProgress2());
        model.addAttribute("myColProList", projectList2);
        List<Project> projectList3 = projectService.findProByUserId(id);
        model.addAttribute("myProList", projectList3);
        model.addAttribute("orderList", projectList);
            return "myHome";
    }
}
